Public Class Header
    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents litNavigation As System.Web.UI.WebControls.Literal
    Protected WithEvents lblVersion As System.Web.UI.WebControls.Label
    Protected WithEvents lblReleasedDate As System.Web.UI.WebControls.Label
    Protected WithEvents lblUsername As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private _navBar As NavigationBarItemCollection

    Public ReadOnly Property NavigationBar() As NavigationBarItemCollection
        Get
            If IsNothing(_navBar) Then
                _navBar = New NavigationBarItemCollection
            End If
            Return _navBar
        End Get
    End Property

    Public Property MenuIndex() As EMenuIndex
        Get
            If IsNothing(ViewState("MenuIndex")) Then
                ViewState("MenuIndex") = 0
            End If
            Return CType(ViewState("MenuIndex"), EMenuIndex)
        End Get
        Set(ByVal Value As EMenuIndex)
            ViewState("MenuIndex") = Value
        End Set
    End Property

    Private Function RenderNavigationBar() As String
        Dim navBarItem As NavigationBarItem
        Dim i As Integer
        Dim s As String = ""

        For i = 0 To Me.NavigationBar.Count - 1
            navBarItem = NavigationBar.Item(i)

            If navBarItem.Url <> "" Then
                s &= String.Format("<b><a href={0}>{1}</a></b>", navBarItem.Url, navBarItem.Text)
            Else
                s &= String.Format("<b>{0}</b>", navBarItem.Text)
            End If

            s &= " | "
        Next

        If NavigationBar.Count > 0 Then
            s = s.Substring(0, s.Length - 3)
        End If

        Return s
    End Function

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Me.IsPostBack Then
            Me.litNavigation.Text = Me.RenderNavigationBar()
            lblUsername.Text = Security.GetCurrentUser().Name

            ' Get directory where assembly has just been installed from the assembly information
            Dim Asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
            Dim fiTemp As System.IO.FileInfo = New System.IO.FileInfo(Asm.Location)

            Dim sVer As String = Asm.GetName.Version.ToString
            sVer = sVer.Substring(0, sVer.LastIndexOf("."c))
            Me.lblVersion.Text = sVer

            Me.lblReleasedDate.Text = FormatDate(fiTemp.CreationTime)
        End If
    End Sub

    Protected Function UserType() As Byte        
        Return Security.GetCurrentUser().UserType
    End Function

    Protected Function IsAdmin() As Boolean
        Return Security.IsAdmin
    End Function
End Class

Public Enum EMenuIndex As Byte
    InternalOrderList
    InternalReport
    InternalUserList
    CustomerOrderList
    CustomerWeeklyReport
    CustomerHistoryReport
End Enum
